package com.novanok.mailtweets.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;


import com.novanok.mailtweets.R;
import com.novanok.mailtweets.comun.Comun;
import com.novanok.mailtweets.entidad.Cuenta;

import java.util.ArrayList;

public class ListaCuentaAdapter extends BaseAdapter {

    ArrayList<Cuenta> myList = new ArrayList<Cuenta>();
    LayoutInflater inflater;
    Context context;

    public ListaCuentaAdapter( Context context, ArrayList<Cuenta> myList ) {
        this.myList = myList;
        this.context = context;
        inflater = LayoutInflater.from( this.context );
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return myList.size();
    }

    @Override
    public Cuenta getItem(int arg0) {
        // TODO Auto-generated method stub
        return myList.get(arg0);
    }

    @Override
    public long getItemId(int arg0) {
        // TODO Auto-generated method stub
        return arg0;
    }

    @Override
    public View getView( int arg0, View arg1, ViewGroup arg2 ) {
        if (arg1 == null) {
            arg1 = inflater.inflate( R.layout.list_item_cuenta, arg2, false );
        }

        ImageView image = (ImageView)arg1.findViewById(R.id.imgProfile);
        TextView nombre = (TextView)arg1.findViewById(R.id.txtNombre);
        TextView descripcion = (TextView)arg1.findViewById(R.id.txtDescripcion);

        synchronized ( myList ) {
            Cuenta msg = myList.get(arg0);

            image.setImageBitmap(Comun.getBitmapFromURL(msg.getImagenPerfil()));
            nombre.setText("@" + msg.getNombre());
            descripcion.setText(msg.getDescripcion());
        }

        return arg1;
    }
}